package com.weihui.jxc.view.goods;

import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

import com.weihui.jxc.common.CommonFactory;
import com.weihui.jxc.common.Constants;
import com.weihui.jxc.model.Goods;
import com.weihui.jxc.model.GoodsInfo;
import com.weihui.jxc.model.Item;
import com.weihui.jxc.model.Provider;
import com.weihui.jxc.service.GoodsService;
import com.weihui.jxc.service.ProviderService;
import com.weihui.jxc.view.CustomerInternalFrame;
import com.weihui.jxc.view.GoodsInternalFrame;

import javax.swing.JButton;
import javax.swing.JComboBox;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
/**
 * 商品信息修改、删除面板
 * @author xiaowei
 *
 */
public class GoodsEditPanel extends JPanel implements ActionListener{
	private JTextField nameTf;
	private JTextField shortTf;
	private JTextField placeTf;
	private JTextField sizeTf_1;
	private JTextField packageTf;
	private JTextField productCodeTf;
	private JTextField pCodeTf;
	private JTextField priceTf;
	private JTextField memoTf;
	private JComboBox comboBox_1;// 选择商品
	private JComboBox comboBox;// 选择供应商
	private GoodsService goodsService;
	private ProviderService providerService;

	/**
	 * Create the panel.
	 */
	public GoodsEditPanel() {

		JPanel panel = new JPanel();

		JPanel panel_1 = new JPanel();

		shortTf = new JTextField();
		shortTf.setColumns(20);

		JLabel label = new JLabel("商品简称：");
		label.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/商品简称.png")));
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGap(0, 522, Short.MAX_VALUE)
				.addGroup(gl_panel_1.createSequentialGroup().addContainerGap().addComponent(label)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(shortTf, GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE).addContainerGap()));
		gl_panel_1.setVerticalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGap(0, 49, Short.MAX_VALUE)
				.addGroup(gl_panel_1.createSequentialGroup().addContainerGap()
						.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(label).addComponent(
								shortTf, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE))
						.addContainerGap(24, Short.MAX_VALUE)));
		panel_1.setLayout(gl_panel_1);

		JPanel panel_2 = new JPanel();

		placeTf = new JTextField();
		placeTf.setColumns(20);

		JLabel label_1 = new JLabel("商品产地：");
		label_1.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/地址.png")));
		GroupLayout gl_panel_2 = new GroupLayout(panel_2);
		gl_panel_2.setHorizontalGroup(gl_panel_2.createParallelGroup(Alignment.LEADING).addGap(0, 522, Short.MAX_VALUE)
				.addGroup(gl_panel_2.createSequentialGroup().addContainerGap().addComponent(label_1)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(placeTf, GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE).addContainerGap()));
		gl_panel_2.setVerticalGroup(gl_panel_2.createParallelGroup(Alignment.LEADING).addGap(0, 49, Short.MAX_VALUE)
				.addGroup(gl_panel_2.createSequentialGroup().addContainerGap()
						.addGroup(gl_panel_2.createParallelGroup(Alignment.BASELINE).addComponent(label_1).addComponent(
								placeTf, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE))
						.addContainerGap(24, Short.MAX_VALUE)));
		panel_2.setLayout(gl_panel_2);

		JPanel panel_3 = new JPanel();

		sizeTf_1 = new JTextField();
		sizeTf_1.setColumns(20);

		JLabel sizeTf = new JLabel("商品规格：");
		sizeTf.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/运-规格.png")));

		JLabel label_2 = new JLabel("商品包装：");
		label_2.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/包装.png")));

		packageTf = new JTextField();
		packageTf.setColumns(20);
		GroupLayout gl_panel_3 = new GroupLayout(panel_3);
		gl_panel_3.setHorizontalGroup(
			gl_panel_3.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_3.createSequentialGroup()
					.addContainerGap()
					.addComponent(sizeTf)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(sizeTf_1, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
					.addGap(37)
					.addComponent(label_2)
					.addGap(2)
					.addComponent(packageTf, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(36, Short.MAX_VALUE))
		);
		gl_panel_3.setVerticalGroup(
			gl_panel_3.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_3.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_3.createParallelGroup(Alignment.BASELINE)
						.addComponent(sizeTf)
						.addComponent(sizeTf_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(label_2)
						.addComponent(packageTf, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(15, Short.MAX_VALUE))
		);
		panel_3.setLayout(gl_panel_3);

		JPanel panel_4 = new JPanel();

		JLabel label_3 = new JLabel("商品批号：");
		label_3.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/批号.png")));

		productCodeTf = new JTextField();
		productCodeTf.setColumns(20);

		JLabel label_4 = new JLabel("批准文号：");
		label_4.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/批准文号.png")));

		pCodeTf = new JTextField();
		pCodeTf.setColumns(20);
		GroupLayout gl_panel_4 = new GroupLayout(panel_4);
		gl_panel_4.setHorizontalGroup(
			gl_panel_4.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_4.createSequentialGroup()
					.addContainerGap()
					.addComponent(label_3)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(productCodeTf, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
					.addComponent(label_4, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(pCodeTf, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
					.addGap(32))
		);
		gl_panel_4.setVerticalGroup(
			gl_panel_4.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_4.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_4.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_4.createParallelGroup(Alignment.BASELINE)
							.addComponent(label_4)
							.addComponent(pCodeTf, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panel_4.createParallelGroup(Alignment.BASELINE)
							.addComponent(label_3)
							.addComponent(productCodeTf, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(15, Short.MAX_VALUE))
		);
		panel_4.setLayout(gl_panel_4);

		JPanel panel_5 = new JPanel();

		JLabel label_5 = new JLabel("商品价格：");
		label_5.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/价格.png")));

		priceTf = new JTextField();
		priceTf.setColumns(20);
		GroupLayout gl_panel_5 = new GroupLayout(panel_5);
		gl_panel_5.setHorizontalGroup(gl_panel_5.createParallelGroup(Alignment.LEADING).addGap(0, 522, Short.MAX_VALUE)
				.addGroup(gl_panel_5.createSequentialGroup().addContainerGap().addComponent(label_5)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(priceTf, GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE).addContainerGap()));
		gl_panel_5.setVerticalGroup(gl_panel_5.createParallelGroup(Alignment.LEADING).addGap(0, 49, Short.MAX_VALUE)
				.addGroup(gl_panel_5.createSequentialGroup().addContainerGap()
						.addGroup(gl_panel_5.createParallelGroup(Alignment.BASELINE).addComponent(label_5).addComponent(
								priceTf, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE))
						.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
		panel_5.setLayout(gl_panel_5);

		JPanel panel_6 = new JPanel();

		JLabel label_6 = new JLabel("商品备注：");
		label_6.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/备注.png")));

		memoTf = new JTextField();
		memoTf.setColumns(20);
		GroupLayout gl_panel_6 = new GroupLayout(panel_6);
		gl_panel_6.setHorizontalGroup(gl_panel_6.createParallelGroup(Alignment.LEADING).addGap(0, 522, Short.MAX_VALUE)
				.addGroup(gl_panel_6.createSequentialGroup().addContainerGap().addComponent(label_6)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(memoTf, GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE).addContainerGap()));
		gl_panel_6.setVerticalGroup(gl_panel_6.createParallelGroup(Alignment.LEADING).addGap(0, 49, Short.MAX_VALUE)
				.addGroup(gl_panel_6.createSequentialGroup().addContainerGap()
						.addGroup(gl_panel_6.createParallelGroup(Alignment.BASELINE).addComponent(label_6).addComponent(
								memoTf, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE))
						.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
		panel_6.setLayout(gl_panel_6);

		JPanel panel_7 = new JPanel();

		JLabel label_7 = new JLabel("供应商全称：");

		comboBox = new JComboBox();
		comboBox.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

			}
		});
		GroupLayout gl_panel_7 = new GroupLayout(panel_7);
		gl_panel_7.setHorizontalGroup(gl_panel_7.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_7.createSequentialGroup().addContainerGap().addComponent(label_7)
						.addPreferredGap(ComponentPlacement.RELATED).addComponent(comboBox, 0, 398, Short.MAX_VALUE)
						.addContainerGap()));
		gl_panel_7.setVerticalGroup(gl_panel_7.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_7
				.createSequentialGroup().addContainerGap()
				.addGroup(gl_panel_7.createParallelGroup(Alignment.BASELINE).addComponent(label_7).addComponent(
						comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
				.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
		panel_7.setLayout(gl_panel_7);

		JPanel panel_8 = new JPanel();

		JPanel panel_9 = new JPanel();

		JLabel label_8 = new JLabel("选择商品：");

		comboBox_1 = new JComboBox();
		comboBox_1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// 选择商品
				selectGoods();

			}
		});
		GroupLayout gl_panel_9 = new GroupLayout(panel_9);
		gl_panel_9.setHorizontalGroup(gl_panel_9.createParallelGroup(Alignment.LEADING).addGap(0, 522, Short.MAX_VALUE)
				.addGroup(gl_panel_9.createSequentialGroup().addContainerGap().addComponent(label_8)
						.addPreferredGap(ComponentPlacement.RELATED).addComponent(comboBox_1, 0, 398, Short.MAX_VALUE)
						.addContainerGap()));
		gl_panel_9.setVerticalGroup(gl_panel_9.createParallelGroup(Alignment.LEADING).addGap(0, 49, Short.MAX_VALUE)
				.addGroup(gl_panel_9.createSequentialGroup().addContainerGap()
						.addGroup(gl_panel_9.createParallelGroup(Alignment.BASELINE).addComponent(label_8).addComponent(
								comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE))
						.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
		panel_9.setLayout(gl_panel_9);
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.TRAILING).addGroup(Alignment.LEADING,
				groupLayout.createSequentialGroup().addContainerGap().addGroup(groupLayout
						.createParallelGroup(Alignment.LEADING)
						.addComponent(panel_8, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
						.addComponent(panel, GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
						.addComponent(panel_1, GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
						.addComponent(panel_2, GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
						.addComponent(panel_3, GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
						.addComponent(panel_4, GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
						.addComponent(panel_5, GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
						.addComponent(panel_6, GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
						.addComponent(panel_7, GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
						.addComponent(panel_9, GroupLayout.PREFERRED_SIZE, 522, GroupLayout.PREFERRED_SIZE))
						.addContainerGap()));
		groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup().addContainerGap()
						.addComponent(panel, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_2, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_3, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_4, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_5, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_6, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_7, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_9, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED).addComponent(panel_8, GroupLayout.PREFERRED_SIZE,
								GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(29, Short.MAX_VALUE)));

		JButton updateBtn = new JButton("修改");
		updateBtn.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/修 改.png")));
		updateBtn.addActionListener(this);
		panel_8.add(updateBtn);

		JButton deleteBtn = new JButton("删除");
		deleteBtn.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/取消.png")));
		deleteBtn.addActionListener(this);
		panel_8.add(deleteBtn);

		JLabel lblNewLabel = new JLabel("商品名称：");
		lblNewLabel.setIcon(new ImageIcon(GoodsEditPanel.class.getResource("/images/商品名称.png")));

		nameTf = new JTextField();
		nameTf.setColumns(20);
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup().addContainerGap().addComponent(lblNewLabel)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(nameTf, GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE).addContainerGap()));
		gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel
				.createSequentialGroup().addContainerGap()
				.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel).addComponent(
						nameTf, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
				.addContainerGap(24, Short.MAX_VALUE)));
		panel.setLayout(gl_panel);
		setLayout(groupLayout);
		setBounds(10, 10, 550, 565);
		goodsService = CommonFactory.getGoodsService();
		providerService = CommonFactory.getProviderService();
		// 初始化商品下拉列表框
		initGoodsComboBox();
		// 初始化供应商下拉列表框
		initProviderComboBox();
	}

	/**
	 * 初始化商品下拉选择框
	 */
	public void initGoodsComboBox() {
		GoodsInfo g;
		// 获取数据库中的数据
		List<GoodsInfo> list = goodsService.findGoods(null);
		// 设置下来列表框中数据模型
		Vector<Item> items = new Vector<>();
		items.clear();
		// 清空下拉列表框中的内容，免的重复
		comboBox_1.removeAllItems();
		// 迭代处理数据
		for (int i = 0; i < list.size(); i++) {
			Item item = new Item();
			item.setId(list.get(i).getId());
			item.setName(list.get(i).getGoodsname());
			if (items.contains(item)) {// 如果集合中包含该元素，就不在添加
				continue;
			}
			items.add(item);
			comboBox_1.addItem(item);
		}
	}

	/**
	 * 初始化供应商下拉选择框
	 */
	public void initProviderComboBox() {
		// 获取数据库中的数据
		List<Provider> list = providerService.findProviders(null);
		// 设置下来列表框中数据模型
		Vector<Item> items = new Vector<>();
		// 清空下拉列表框中的内容，免的重复
		comboBox.removeAllItems();
		// 迭代处理数据
		for (int i = 0; i < list.size(); i++) {
			Item item = new Item();
			item.setId(list.get(i).getId());
			item.setName(list.get(i).getCustomerName());
			if (items.contains(item)) {// 如果集合中包含该元素，就不在添加
				continue;
			}
			items.add(item);
			comboBox.addItem(item);
		}
	}

	/**
	 * 下拉列表框点击事件
	 */
	private void selectGoods() {
		Item goodsItem;
		if (!(comboBox_1.getSelectedItem() instanceof Item)) {
			return;
		}
		goodsItem = (Item) comboBox_1.getSelectedItem();
		System.out.println(goodsItem.getId() + "," + goodsItem.getName());
		// 根据商品编号查询数据库
		Goods g = new Goods();
		g.setId(goodsItem.getId());
		List<Goods> list = goodsService.findGoods(g);
		// 更新View
		setData(list.get(0));

	}

	/**
	 * 刷新View
	 */
	private void setData(Goods g) {
		nameTf.setText(g.getGoodsname());
		shortTf.setText(g.getShorts());
		placeTf.setText(g.getProductplace());
		sizeTf_1.setText(g.getSize());
		packageTf.setText(g.getPackages());
		productCodeTf.setText(g.getProductcode());
		pCodeTf.setText(g.getPromitcode());
		priceTf.setText(g.getPrice() + "");
		memoTf.setText(g.getMemo());
		// 同步更新 供应商下拉列表框的选中的值
		for (int i = 0; i < comboBox.getItemCount(); i++) {
			Item providerItem = (Item) comboBox.getItemAt(i);
			System.out.println(i + "," + providerItem.getId() + "====" + g.getProviderId());
			if (providerItem.getId().equals(g.getProviderId())) {
				comboBox.setSelectedIndex(i);// 通过下标的方式
				// comboBox.setSelectedItem(providerItem);
			}
		}

	}

	/**
	 * 点击事件
	 * 
	 * @param arg0
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		String target = e.getActionCommand();
		switch (target) {
		case "修改":
			  //非空验证
			Item selectItem = (Item) comboBox.getSelectedItem();
			Boolean isTrue =  GoodsInternalFrame.dataCheck(nameTf.getText().trim(), shortTf.getText().trim(), 
					placeTf.getText().trim(),sizeTf_1.getText().trim() , 
					packageTf.getText().trim(), productCodeTf.getText().trim(), 
					pCodeTf.getText().trim(), priceTf.getText().trim(), 
					memoTf.getText().trim(), selectItem.getId());
			
			if(isTrue == true) {
							//获取商品的Id
			String goodsId =((Item)(comboBox_1.getSelectedItem())).getId();
			//获取供应商的Id
			String providerId =((Item)(comboBox.getSelectedItem())).getId();
			//封装数据
			Goods goods = new Goods(goodsId, 
					nameTf.getText().trim(), shortTf.getText().trim(), 
					placeTf.getText().trim(), sizeTf_1.getText().trim(), 
					packageTf.getText().trim(), productCodeTf.getText().trim(),
					pCodeTf.getText().trim(), Float.parseFloat(priceTf.getText().trim()),
					memoTf.getText().trim(), providerId);
			//修改数据
			boolean isFlag = goodsService.updateGoods(goods);
			if(isFlag==true) {
				JOptionPane.showMessageDialog(null, "商品信息修改成功！","提示",JOptionPane.INFORMATION_MESSAGE);
				initGoodsComboBox();//刷新界面
				
			}else {
				JOptionPane.showMessageDialog(null, "商品信息修改失败！","警告",JOptionPane.WARNING_MESSAGE);			
			}
			}else {
				JOptionPane.showMessageDialog(null, "填写的数据非法，请认真检查！","警告",JOptionPane.WARNING_MESSAGE);
			}

			break;
		case "删除":
            int result = JOptionPane.showConfirmDialog(null, "您确定要删除该商品吗？", "提示", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
            if(result==0) {
            	//获取商品的Id
    			String gId =((Item)(comboBox_1.getSelectedItem())).getId();
    			boolean isflag = goodsService.updateGoods(gId, Constants.DATA_DEL);
    			if(isflag==true) {
    				JOptionPane.showMessageDialog(null, "商品信息删除成功！","提示",JOptionPane.INFORMATION_MESSAGE);
    				initGoodsComboBox();//刷新界面
    			}else {
    				JOptionPane.showMessageDialog(null, "商品信息删除失败！","警告",JOptionPane.WARNING_MESSAGE);			
    			}
            }
			break;
		default:
			break;
		}

	}
}